package com.oddfar.campus.business.controller;

import com.oddfar.campus.business.domain.ClTcw;
import com.oddfar.campus.business.domain.Tcwxx;
import com.oddfar.campus.business.mapper.ClTcwMapper;
import com.oddfar.campus.business.service.ClTcwService;
import com.oddfar.campus.common.domain.PageResult;
import com.oddfar.campus.common.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/fjdcgl/clTcw", name = "车辆停车位")
public class ClTcwController {


    @Autowired
    private ClTcwService clTcwService;

    @Autowired
    private ClTcwMapper clTcwMapper;

    @RequestMapping(value = "/list", name = "查询预约列表")
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    public R list(ClTcw clTcw) {
        PageResult<ClTcw> page = clTcwService.page(clTcw);
        return R.ok().put(page);
    }

    /*
    可预约位置查询
     */
    @RequestMapping(value = "/dqkyztcx", name = "当前可用状态查询")
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    public R dqkyztcx() {
        List<Tcwxx> list = clTcwMapper.dqkyztcx();
        return R.ok().put(list);
    }


    /**
     * 获取车辆详细信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @GetMapping(value = "/{djxh}", name = "获取预约详细信息")
    public R getInfo(@PathVariable("djxh") Long djxh) {
        return R.ok(clTcwMapper.selectById(djxh));
    }

    /**
     * 新增预约信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @PostMapping(name = "新增预约信息")
    public R add(@RequestBody ClTcw clTcw) {
        return R.ok(clTcwService.insertClTcw(clTcw));
    }

    /**
     * 修改预约信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @PutMapping(name = "修改预约信息")
    public R edit(@RequestBody ClTcw clTcw) {
        return R.ok(clTcwService.updateClTcw(clTcw));
    }

    /**
     * 删除预约信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @DeleteMapping(value = "/{uuid}", name = "删除预约信息")
    public R remove(@PathVariable String uuid) {
        return R.ok(clTcwMapper.deleteClTcw(uuid));
    }

}
